package com.xieyong.mywebsite.service.Impl;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xieyong.mywebsite.mapper.BaseDictMapper;
import com.xieyong.mywebsite.model.entity.BaseDict;
import com.xieyong.mywebsite.service.BaseDictService;
import com.xieyong.mywebsite.util.TokenUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BaseDictServiceImpl implements BaseDictService {

    @Resource
    private BaseDictMapper baseDictMapper;

    @Override
    public BaseDict selectOne(Integer id) {
        return baseDictMapper.selectOne(id);
    }

    @Override
    public BaseDict selectOneByDictId(String dictId) {
        return baseDictMapper.selectOneByDictId(dictId);
    }

    @Override
    public BaseDict selectOneByDictName(String name) {
        return baseDictMapper.selectOneByDictName(name);
    }

    @Override
    public List<BaseDict> selectAll() {
        return baseDictMapper.selectAll();
    }

    @Override
    public List<BaseDict> selectDictsByTopId(String topId) {
        return baseDictMapper.selectDictsByTopId(topId);
    }

    @Override
    public List<BaseDict> selectDictsByPreID(String preId) {
        return baseDictMapper.selectDictsByPreID(preId);
    }

    @Override
    public PageInfo<BaseDict> selectPage(Integer pageNum, Integer pageSize, String topId, String preId, String name) {
        PageHelper.startPage(pageNum, pageSize);
        List<BaseDict> dicts = baseDictMapper.selectByCondition(topId,preId,name);
        return PageInfo.of(dicts);
    }

    @Override
    public void insert(BaseDict BaseDict) {
        baseDictMapper.insert(BaseDict);
    }

    @Override
    public void update(BaseDict BaseDict) {
        baseDictMapper.update(BaseDict);
    }

    @Override
    public void delete(Integer id) {
        baseDictMapper.delete(DateUtil.date(), TokenUtil.getCurrentUser().getId(),id);
    }

    @Override
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            baseDictMapper.delete(DateUtil.date(), TokenUtil.getCurrentUser().getId(),id);
        }
    }

    @Override
    public void switchActive(Integer id) {
        baseDictMapper.switchActive(id);

    }

    @Override
    public void switchBatchActive(List<Integer> ids) {
        for (Integer id : ids) {
            baseDictMapper.switchActive(id);
        }
    }
}
